﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace ParticlesEngine
{
    /*!
	\class ParticlesSystemEngine
	\brief
		Particles systems engine implementation. Singleton.
		\tparam T: allele type, eye color, height, etc...
		\tparam C: allele class.
    */
    class ParticlesSystemEngine
    {
        //Singleton
         private static ParticlesSystemEngine engine = null;

         //particles list
         List<ParticlesSystem> systemsList = new List<ParticlesSystem>();
         
         //TODO eliminar
        ContentManager content;
        GraphicsDeviceManager graphics;
        Matrix worldMatrix;
        Matrix viewMatrix;
        Matrix projectionMatrix;

         public static ParticlesSystemEngine GetInstance()
         {
             if (engine == null) engine = new ParticlesSystemEngine();

             return engine;
         }
         public void update(double timeElapsed){
             foreach (ParticlesSystem ps in systemsList) {
                 if (ps.isEnabled()) ps.updateSystem(timeElapsed);
             }
         }
         public void render() {
             foreach (ParticlesSystem ps in systemsList) {
                 if(ps.isEnabled()) ps.renderSystem();
             }
         }
         public void load() {
             //loading smoke particle system
             SmokeParticlesSystem sps = new SmokeParticlesSystem(100);
             ParticleEmitter pe = new ParticleEmitter(new Vector3(0,0,300), 10, 10);
             sps.addParticleEmitter(pe);
             sps.enable(true);
             add(sps);
         }
         public void initialize(ContentManager c, GraphicsDeviceManager g, Matrix world, Matrix view, Matrix projection)
         {
             content = c;
             graphics = g;
             worldMatrix = world;
             viewMatrix = view;
             projectionMatrix = projection;

             foreach(ParticlesSystem ps in systemsList) {
                 ps.initializeSystem();
             }
         }
         public ContentManager getContentManager() { return content; }
         public GraphicsDeviceManager getGraphicsDeviceManager() { return graphics; }
         public void setCameraMatrix(Matrix world, Matrix view, Matrix projection) {
             worldMatrix = world;
             viewMatrix = view;
             projectionMatrix = projection;
         }
         public Matrix getWorldMatrix() { return worldMatrix; }
         public Matrix getViewMatrix() { return viewMatrix; }
         public Matrix getProjectionMatrix() { return projectionMatrix; }
         public void destroy() { 
         }
         void add(ParticlesSystem ps) {
             systemsList.Add(ps);
         }
    }
}
